package config
{
    import kernel.config.ConfigData;

    public class ColorConfig
    {
        private static var _instance:ColorConfig;

        private var _defaultBlack:uint;
        private var _defaultWhite:uint;
        private var _defaultYellow:uint;
        private var _defaultRed:uint;
        private var _defaultGreen:uint;
        private var _defaultBlue:uint;
        private var _defaultPurple:uint;
        private var _data:XML;

        public var mineColor:uint;
        public var friendColor:uint;
        public var strangerColor:uint;
        public var blackColor:uint;
        public var hostilityColor:uint;
        public var neutralColor:uint;


        public static function get instance():ColorConfig
        {
            if (_instance == null)
            {
                _instance = new ColorConfig ();
            }
            return _instance;
        }

        public function ColorConfig()
        {

            _data = ConfigData.getXML ("color");

            var defaultXML:XML = _data.default[0];

            _defaultBlack = defaultXML.black;
            _defaultWhite = defaultXML.white;
            _defaultYellow = defaultXML.yellow;
            _defaultRed = defaultXML.red;
            _defaultGreen = defaultXML.green;
            _defaultBlue = defaultXML.blue;
            _defaultPurple = defaultXML.purple;

            var minimap:XML = _data.minimap[0];
            mineColor = uint (minimap.mine);
            friendColor = uint (minimap.friend);
            strangerColor = uint (minimap.stranger);
            blackColor = uint (minimap.black);
            hostilityColor = uint (minimap.hostility);
            neutralColor = uint (minimap.neutral);

        }

        public function getIslandPopularityColor():Array
        {
            var arr:Array = _data.islandPopularity[0].toString ().split ("|");
            for (var i:int = 0 ; i < arr.length ; i++)
            {
                arr[i] = uint (arr[i]);
            }
            return arr;
        }

        public function get defaultBlack():uint
        {
            return _defaultBlack;
        }

        public function get defaultWhite():uint
        {
            return _defaultWhite;
        }

        public function get defaultYellow():uint
        {
            return _defaultYellow;
        }

        public function get defaultRed():uint
        {
            return _defaultRed;
        }

        public function get defaultGreen():uint
        {
            return _defaultGreen;
        }

        public function get defaultBlue():uint
        {
            return _defaultBlue;
        }

        public function get defaultPurple():uint
        {
            return _defaultPurple;
        }

        public function getChatChannelColor(channelID:uint):uint
        {
            return _data.chat.channels.channel.(@id == channelID);
        }

        public function getChatPlayerNameColor(sex:uint):uint
        {
            return _data.chat.player.name.(@sex == sex);
        }
    }
}
